﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Controller;
using Entity;

namespace Web
{
    public partial class CreateCustomer : System.Web.UI.Page
    {
        Helper helper = new Helper();
        CustomerEntity customerEntity = new CustomerEntity();
        CustomerController customerController = new CustomerController();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.PreRender += new EventHandler(UpdateFlashMessage);
        }
        private void UpdateFlashMessage(object sender, EventArgs e)
        {
            helper.ShowFlashMessage(FlashMessageLabel);
        }

        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            customerEntity = new CustomerEntity();

            customerEntity.Name = NameTextBox.Text.Trim();
            customerEntity.ShortName = ShortNameTextBox.Text.Trim();
            customerEntity.Address = ShortNameTextBox.Text.Trim();
            customerEntity.Phone = PhoneTextBox.Text.Trim();
            customerEntity.Fax = FaxTextBox.Text.Trim();
            customerEntity.Email = EmailTextBox.Text.Trim();
            customerEntity.ContactPerson = ContactPersonTextBox.Text.Trim();
            customerEntity.ZipCode = ZipCodeTextBox.Text.Trim();
            customerEntity.Number = Convert.ToInt32(NumberTextBox.Text.Trim());
            customerEntity.Code = CodeTextBox.Text.Trim();
            customerEntity.Remark = RemarkTextBox.Text.Trim();
            bool result = customerController.AddCustomer(customerEntity);
            if (result == true)
            {
                Session["FlashMessage"] = "Success: Create Customer Successful!";
                Session["FlashMessageType"] = "success";
            }
            else
            {
                Session["FlashMessage"] = "Error: Create Customer unsuccessful!";
                Session["FlashMessageType"] = "error";
            }

        }



        protected void CancelButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/CustomerList.aspx");
        }
    }
}